package cn.javadog.cloud.starter.limiter.config;

import cn.javadog.cloud.starter.limiter.interceptor.AccessLimitAspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author yuy
 * @date 2020-11-06 16:35
 * 自动配置类
 **/
@Configuration
@EnableConfigurationProperties(LimiterProperties.class)
public class LimiterAutoConfiguration {

    @Resource
    private LimiterProperties limiterProperties;

    @Bean
    @ConditionalOnProperty(prefix = "starter.limiter", value = "enabled", havingValue = "true")
    public AccessLimitAspect accessLimitAspect(){
        return new AccessLimitAspect(limiterProperties.getPrefix());
    }

}
